# !/usr/bin/env python
# -*- coding: utf-8 -*-
from arr_util import random_scale_arr


# 基数排序


def radix_sort(num_arr):
    min_num = min(num_arr)
    max_num = max(num_arr)
    min_len = len(str(min_num))
    max_len = len(str(max_num))

    for i in range(min_len, max_len + 1):
        level = pow(10, i - 1)

        key_arr = []
        for k in range(0, 10):
            key_arr.append([])
        for num in num_arr:
            mod = num // level % 10
            key_arr[mod].append(num)
        num_index = 0
        for k in range(0, 10):
            ele_arr = key_arr[k]
            for e in ele_arr:
                num_arr[num_index] = e
                num_index += 1


if __name__ == '__main__':
    arr = [1, 2, 5, 7, 6, 5, 4]
    radix_sort(arr)
    print(arr)
    arr2 = random_scale_arr(20, 500)
    radix_sort(arr2)
    print(arr2)
